<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'password',
        'open_id',
        'team_id',
        'avatar',
        'growing_coffee',
        'point',
        'phone_number',
        'remember_token'
    ];

    protected $with = ['team'];

    public function team()
    {
        return $this->belongsTo(Team::class, 'team_id');
    }

    public function apply()
    {
        return $this->hasOne(Apply::class, 'user_id');
    }

    public function coupons()
    {
        return $this->hasMany(Coupon::class, 'user_id')->orderBy('expired_at')->orderBy('type');
    }

    public function dispatch_free_logs()
    {
        return $this->hasMany(DispatchFreeLog::class, 'user_id');
    }

    public function orders()
    {
        return $this->hasMany(Order::class, 'user_id');
    }

    public function pointLogs()
    {
        return $this->hasMany(PointLog::class, 'user_id');
    }

    public function PointBagLogs()
    {
        return $this->hasMany(PointBagLog::class, 'user_id');
    }


}
